<html>
<!-- =====================================================================

  File:      usp_ReviewsAdd.htm for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     June 16, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
    <head>
        <title>Adventure Works Cycles Store Documentation</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <h1>"usp_ReviewsAdd" Stored Procedure</h1>

        <b>Description:</b>

        <P>This stored procedure adds an entry to the Reviews table for the product being
        reviewed.&nbsp; It returns the newly added ReviewID in an output parameter.</P>

        <b>Definition:</b>

<pre style="background-color:white">
<span style="color: #0000FF"><strong>CREATE</strong></span> Procedure usp_ReviewsAdd
<span style="color: #4444FF">(</span>
    @ProductID     <span style="color: #2040a0"><strong>int</strong></span><span style="color: #4444FF">,</span>
    @CustomerName  <span style="color: #2040a0"><strong>nvarchar</strong></span><span style="color: #4444FF">(</span>50<span style="color: #4444FF">)</span><span style="color: #4444FF">,</span>
    @CustomerEmail <span style="color: #2040a0"><strong>nvarchar</strong></span><span style="color: #4444FF">(</span>50<span style="color: #4444FF">)</span><span style="color: #4444FF">,</span>
    @Rating        <span style="color: #2040a0"><strong>int</strong></span><span style="color: #4444FF">,</span>
    @Comments      <span style="color: #2040a0"><strong>nvarchar</strong></span><span style="color: #4444FF">(</span>3850<span style="color: #4444FF">)</span><span style="color: #4444FF">,</span>
    @ReviewID      <span style="color: #2040a0"><strong>int</strong></span> OUTPUT
<span style="color: #4444FF">)</span>
<span style="color: #0000FF"><strong>AS</strong></span>

<span style="color: #0000FF"><strong>INSERT</strong></span> <span style="color: #0000FF"><strong>INTO</strong></span> Production.ProductReview
<span style="color: #4444FF">(</span>
    ProductID<span style="color: #4444FF">,</span> 
    ReviewerName<span style="color: #4444FF">,</span> 
    EmailAddress<span style="color: #4444FF">,</span> 
    Rating<span style="color: #4444FF">,</span> 
    Comments
<span style="color: #4444FF">)</span>
VALUES
<span style="color: #4444FF">(</span>
    @ProductID<span style="color: #4444FF">,</span> 
    @CustomerName<span style="color: #4444FF">,</span> 
    @CustomerEmail<span style="color: #4444FF">,</span> 
    @Rating<span style="color: #4444FF">,</span> 
    @Comments
<span style="color: #4444FF">)</span>;

<span style="color: #0000FF"><strong>SELECT</strong></span> 
    @ReviewID <span style="color: #4444FF">=</span> SCOPE_IDENTITY<span style="color: #4444FF">(</span><span style="color: #4444FF">)</span>;


</pre>

        <b>Database Tables Used: </b>

        <P><i>ProductReview:</i> &nbsp;&nbsp;The ProductReview table has a many to one relationship to the Product table.&nbsp; The
        ProductReview table contains all product reviews written by users.&nbsp; We decided not to
        create a relationship between CustomerName to the FullName in the Customers
        table to allow for anyone to review a product without logging into the system.&nbsp;
        The ratings used in our implementation range from 1 to 5 stars.&nbsp; The actual
        review text is allowed to be as large as 3850 characters.

        <p>

        <img src="1x1.gif" width=25> <IMG src="../docs/images/ProductReview.gif" width="368" height="181"></p>

    </body>
</html>
